<?

	header("Content-Type: application/xml; charset=UTF-8"); 

    echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?><rss version=\"2.0\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://web.resource.org/cc/\"><channel><title>Xpert Feed aggregation</title><link>http://www.nottingham.ac.uk/xpert/RSS3/rss.php</link><description>This RSS feed contains a list of all the syndicated content from Xpert</description><generator>Xpert</generator><language>en-gb</language><copyright>http://creativecommons.org/licenses/by-nc-sa/2.0/uk/ </copyright><lastBuildDate>" . date("D, d M Y G:i:s", time()-10000) . " GMT</lastBuildDate><pubDate>" . date("D, d M Y G:i:s",time()-10000) . " GMT</pubDate><dc:publisher>Xpert</dc:publisher><cc:license></cc:license>";

	include "xpert_database.php";
	
	xpert_database_connect($xpert_site);
	
	xpert_database_select($xpert_site);
	
	$query = "select * from xpert_core_scratch";
	
	$site_items = xpert_database_multiple_select_query($query, $xpert_site);
	
	while($site_items_object = xpert_database_fetch_object_from_response($site_items)){
	
		echo "<item><title><![CDATA[" . $site_items_object->resource_title . "]]></title><dc:title><![CDATA[" . $site_items_object->resource_title . "]]></dc:title><link>" . $site_items_object->resource_link . "</link><dc:date>" . $site_items_object->resource_date . "</dc:date>";
		
		$query = "select * from xpert_core_description where resource_id = " . $site_items_object->resource_id;
		
		$site_desc = xpert_database_multiple_select_query($query, $xpert_site);
		
		while($site_desc_object = xpert_database_fetch_object_from_response($site_desc)){
		
			echo "<description><![CDATA[" . utf8_encode(htmlspecialchars($site_desc_object->resource_description)) . "]]>
</description><dc:description><![CDATA[" . utf8_encode(htmlspecialchars($site_desc_object->resource_description)) . "]]>
</dc:description>";
		
		}
		
		echo "<guid isPermaLink=\"true\">" . $site_items_object->resource_link . "</guid>";
		
		$query = "select * from xpert_core_contributor where resource_id = " . $site_items_object->resource_id;
		
		$site_cont = xpert_database_multiple_select_query($query, $xpert_site);
		
		while($site_cont_object = xpert_database_fetch_object_from_response($site_cont)){
		
			echo "<dc:contributor><![CDATA[" . $site_cont_object->resource_contributor . "]]>
</dc:contributor>";
		
		}
		
		$query = "select * from xpert_core_creator where resource_id = " . $site_items_object->resource_id;
		
		$site_creator = xpert_database_multiple_select_query($query, $xpert_site);
		
		while($site_creator_object = xpert_database_fetch_object_from_response($site_creator)){
		
			echo "<dc:creator><![CDATA[" . $site_creator_object->resource_creator. "]]>
</dc:creator>";
		
		}
				
		$query = "select * from xpert_core_type where resource_id = " . $site_items_object->resource_id;
		
		$site_type = xpert_database_multiple_select_query($query, $xpert_site);
		
		while($site_type_object = xpert_database_fetch_object_from_response($site_type)){
		
			echo "<dc:type><![CDATA[" . $site_type_object->resource_type . "]]></dc:type>";
		
		}
		
		$query = "select * from xpert_core_format where resource_id = " . $site_items_object->resource_id;
		
		$site_format = xpert_database_multiple_select_query($query, $xpert_site);
		
		while($site_format_object = xpert_database_fetch_object_from_response($site_format)){
		
			echo "<dc:format><![CDATA[" . $site_format_object->resource_format . "]]></dc:format>";
		
		}
		
		$query = "select * from xpert_core_language where resource_id = " . $site_items_object->resource_id;
		
		$site_language = xpert_database_multiple_select_query($query, $xpert_site);
		
		while($site_language_object = xpert_database_fetch_object_from_response($site_language)){
		
			if($site_language_object->resource_language!="Language not set"){
		
				echo "<dc:language><![CDATA[" . $site_language_object->resource_language . "]]></dc:language>";
				
			}else{
			
			
			}
		
		}
		
		$query = "select * from xpert_core_relation where resource_id = " . $site_items_object->resource_id;
		
		$site_relation = xpert_database_multiple_select_query($query, $xpert_site);
		
		while($site_relation_object = xpert_database_fetch_object_from_response($site_relation)){
		
			echo "<dc:relation><![CDATA[" . $site_relation_object->resource_relation . "]]></dc:relation>";
		
		}
		
		$query = "select * from xpert_core_publisher where resource_id = " . $site_items_object->resource_id;
		
		$site_publisher = xpert_database_multiple_select_query($query, $xpert_site);
		
		while($site_publisher_object = xpert_database_fetch_object_from_response($site_publisher)){
		
			echo "<dc:publisher><![CDATA[" . $site_publisher_object->resource_publisher . "]]></dc:publisher>";
		
		}
		
		$query = "select * from xpert_core_rights where resource_id = " . $site_items_object->resource_id;
		
		$site_rights = xpert_database_multiple_select_query($query, $xpert_site);
		
		while($site_rights_object = xpert_database_fetch_object_from_response($site_rights)){
		
			echo "<dc:rights><![CDATA[" . $site_rights_object->resource_rights . "]]></dc:rights>";
		
		}
		
		$query = "select * from xpert_core_subject where resource_id = " . $site_items_object->resource_id;
		
		$site_subject = xpert_database_multiple_select_query($query, $xpert_site);
		
		while($site_subject_object = xpert_database_fetch_object_from_response($site_subject)){
		
			echo "<dc:subject><![CDATA[" . $site_subject_object->resource_subject . "]]></dc:subject>";
		
		}

		echo "</item>";

	}

	echo "</channel></rss>";
	
?>
